package com.hs.telepass.controller.task;


import android.content.Intent;
import com.hs.telepass.controller.TaskController;
import com.hs.telepass.model.json.response.BaseResponseJson;
import com.hs.telepass.utils.JsonUtil;
import com.hs.telepass.utils.StringUtil;

public class UpdateSessionTask extends Task{
    public final static String ACTION_UPDATE_SESSION_TASK = "action_update_session_task";

    private String jsonRequstStr;
    private String taskUrl;
    private int requestType;

    public UpdateSessionTask(String sessionId, String encrypted_payload){
        jsonRequstStr = "sessionId=" + sessionId + "&" + "encrypted_payload=" + encrypted_payload;
        requestType = TASK_REQUST_TYPE_POST;
        taskUrl = BASE_API_URL + "/" + "bm/session/update";
    }

    @Override
    public void onExecuted(String response, int httpCode) {
        Intent intent = new Intent(getActionName());

        BaseResponseJson json = JsonUtil.fromJson(response, BaseResponseJson.class);

        String code = json.getCode();
        if(!StringUtil.isEmpty(code)){
            intent.putExtra(TaskController.EXTRA_EVENT, TaskController.EVENT_TASK_SUCCEED);
            intent.putExtra(TaskController.EXTRA_RESPONSE, "服务器返回" + code + "状态码" );
        }

        broadcastManager.sendBroadcast(intent);
    }

    @Override
    public int getRequstType() {
        return requestType;
    }

    @Override
    public String getJsonRequstStr() {
        return jsonRequstStr;
    }

    @Override
    public int getResponseSuccessCode() {
        return 0;
    }

    @Override
    public String getTaskUrl() {
        return taskUrl;
    }

    @Override
    public String getActionName() {
        return ACTION_UPDATE_SESSION_TASK;
    }
}
